//
//  UIDevice+JJExtension.swift
//  JJToolSwift
//
//  Created by heihei on 2024/5/9.
//

import Foundation

private func isiPhoneXSeries() -> Bool {
    guard #available(iOS 11.0, *) else { return false }
    return UIApplication.shared.windows[0].safeAreaInsets.bottom > 0
}

public extension UIDevice {
    /// 屏幕尺寸
    static let screenBounds = UIScreen.main.bounds
    /// 屏幕宽
    static let width = UIScreen.main.bounds.width
    /// 屏幕高
    static let height = UIScreen.main.bounds.height
    /// 是否为刘海屏
    static let iPhoneXSeries = isiPhoneXSeries()
    /// 导航栏内容高度
    static let navBarContentHeight = 44.0
    /// tabbar内容高度
    static let tabBarContentHeight = 49.0
    ///导航栏整体高度 状态栏高 + 导航栏内容高
    static let topStatusNavBarHeight = statusBarHeight + navBarContentHeight
    /// 底部tabbar总高度 指示条高 + TabBar高
    static let bottomTabbarIndictorHeight = bottomIndicatorHeight + tabBarContentHeight
    /// 顶部状态栏高度
    static var statusBarHeight: CGFloat {
        if #available(iOS 13.0, *) {
            return window?.windowScene?.statusBarManager?.statusBarFrame.height ?? 0
        } else {
            return UIApplication.shared.statusBarFrame.height
        }
    }
    /// 底部指示条高度
    static var bottomIndicatorHeight: CGFloat {
        if #available(iOS 11.0, *) {
            return window?.safeAreaInsets.bottom ?? 0
        } else {
            return 0
        }
    }
    /// 设备系统版本号
    static let systemVersion = current.systemVersion
    /// 获取当前window
    static var window: UIWindow? {
        if #available(iOS 13.0, *) {
            let winScene = UIApplication.shared.connectedScenes.first as? UIWindowScene
            return winScene?.windows.first
        } else {
            return UIApplication.shared.delegate?.window ?? UIApplication.shared.keyWindow
        }
    }
}
